#define  _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    int maxScore(vector<int>& cardPoints, int k) {
        int n = cardPoints.size();
        k = n - k;
        int cur = 0;
        for (int i = 0; i < k; i++)
            cur += cardPoints[i];

        int sum = cur;
        int Min = cur;

        for (int i = k; i < n; i++)
        {
            cur -= cardPoints[i - k];
            cur += cardPoints[i];
            sum += cardPoints[i];

            Min = min(Min, cur);
        }

        return sum - Min;
    }
};